package com.ch999.mobileoa.page;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.ch999.mobileoa.R;
import com.ch999.mobileoa.request.DataControl;
import com.sda.lib.HttpCore.DataResponse;
import com.sda.lib.util.Tools;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;

import cn.bingoogolapple.qrcode.core.QRCodeView;


/**
 * 二维码扫描界面
 * Created by scorpio on 15/12/28.
 */
public class ScanActivity extends BaseActivity implements QRCodeView.ResultHandler {

    @ViewInject(id = R.id.zbarview)
    QRCodeView qrCodeView ;
    Context context ;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan);
        context = ScanActivity.this ;
        FinalActivity.initInjectedView(this);
    }


    @Override
    protected void onResume() {
        super.onResume();
        qrCodeView.setResultHandler(this);
        qrCodeView.startSpot();
        qrCodeView.startCamera();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        qrCodeView.stopSpot();
        qrCodeView.stopCamera();
    }

    @Override
    public void handleResult(String s) {
        if (s.contains("AppDaka")){
            //APP 考勤打卡
            AppDaka(s);
        }
    }

    /**
     * APP 进行打卡
     * @param s
     */
    private void AppDaka(String s) {
        DataControl.AppDaka(context,s, new DataResponse() {
            @Override
            public void onSucc(Object response) {

            }

            @Override
            public void onFail(String error) {
                Tools.msgbox(context,error);
            }
        });
    }

    @Override
    public void handleCameraError() {

    }

}
